In a multiprocessor system, each processor has a one-level cache or a two-level cache, and multiple copies of one piece of data may simultaneously exist in different caches. If a processor freely modifies their local copies, different processors will observe different results about the data in the different caches. In addition, modification performed by an IO (Input Output, input output) on a main memory may also cause an inconsistency problem. To solve a problem of cache consistency, the MESI (Modified, Exclusive, Shared, Invalid, Modified, Exclusive, Shared, Invalid) protocol is introduced.
In the MESI protocol, each line of temporarily stored data has four states:
an M (modified) modified state: this line has been modified (which is different from that in a main memory) and is available in the current cache;
an E (exclusive) exclusive state: this line is the same as that in the main memory, but is different from that in other caches;
an S (shared) shared state: this line is the same as that in the main memory, but may appear in other caches; and
an I (invalid) invalid state: this line does not include valid data.
A consistency system mainly includes two agents, which are a source agent CA and a target agent HA, where the CA serves as an agent for a cache and an IO, and initiates a request processing response to the HA. Each cache line has a Home, and when no cache has this cache line, all data in this cache line is saved in a memory managed by the HA. In a Home listening mode, a directory corresponding to a cache line is managed by the HA, all requests initiated by the CA are sent to the HA, and the HA listens on another CA according to the directory and responds to the requester CA. The CA and the HA are both modules for managing cache consistency, and may be implemented by using software or hardware.
Types of requests initiated by the CA include:
READE: a request for E-state data;
READS: a request for shared-state data; and
WBI: a write-back request initiated by the CA to the HA, where the CA is in an I state after write back.
Types of listening initiated by the HA include:
SNPE: snooping on the CA, where the CA is in an I state after being snooped on; and
SNPS: snooping on the CA, where the CA is in an I or S state after being snooped on.
Types of CA snooping responses include:
RSPI: the CA returns a snooping response to the HA, where the CA is in an I state after being snooped on;
RSPS: the CA returns a snooping response to the HA, where the CA is in an S state after being snooped on; and
RSPIWB: the CA returns a snooping response with written-back data, where the CA is in an I state after being snooped on.
Types of request responses returned by the HA to the requester CA include:
DATAE: the HA returns an E-state data response to the requester CA; and
DATAS: the HA returns an S-state data response to the requester CA.
The following describes, by using an actual example, a process in which a cache consistency conflict is generated. Referring to FIG. 11, when a CA0 and a CA1 initiate requests for exclusive occupation of same data to the HA, an HA first processes a request from the CA0, and sends a snooping request SNPE to the CA1; after the CA1 returns a response frame RSPI, the HA returns E-state data DATAE to the CA0, and then processes a request from the CA1, and sends a snooping request SNPE to the CA0; if there is a delay for transmitting the returned E-state data DATAE, and the snooping request SNPE reaches the CA0 before the E-state data DATAE reaches the CA0 (in this case, data in the CA0 is in an invalid state), after the CA0 returns the response frame RSPI to the HA, the HA also sends the E-state data DATAE to the CA1, and in this case the E-state data simultaneously exists in the two CAs; as a result, the CA0 and the CA1 each consider that the data is exclusively occupied only by itself in the system, and therefore the CA0 and the CA1 can modify the obtained data (E→M), thereby causing that data saved in the two CAs is inconsistent, and generating a conflict.
To solve the conflict, the following two methods are generally used for processing currently:
In a first method, referring to FIG. 12, when a CA0 and a CA1 initiate exclusive occupation requests for same data to an HA, the HA first processes the request from the CA0, and sends a snooping request SNPE to the CA1; after the CA1 returns a response frame RSPI, the HA returns E-state data DATAE to the CA0, and then processes the request from the CA1, and sends a snooping request SNPE to the CA0; after receiving the snooping request SNPE, the CA0 invalidates the data received by the CA0, and then returns a response frame RSPI to the HA; and after receiving the response frame RSPI, the HA returns the E-state data DATAE to the CA1. In the entire processing procedure, the HA must ensure that the CA0 first receives the E-state data DATAE, and then receives the snooping request SNPE; and finally in the entire system, only the data saved in the CA1 is in an exclusive state.
In a second method, referring to FIG. 13, similarly, when a CA0 and a CA1 initiate exclusive occupation requests for same data to an HA, the HA first processes the request from the CA0, returns E-state data DATAE to the CA0, and then the HA needs to start processing the request from the CA1 only after receiving an acknowledgment frame ACK sent by the CA0; and similarly, after receiving the E-state data DATAE returned by the HA, the CA1 also needs to return an acknowledgment frame ACK to the HA.
In the foregoing first manner, to avoid a conflict, the HA needs to strictly control a sequence of receiving the data response DATAE and the snooping request SNPE at the CA end. In the second manner, one ACK packet needs to be additionally added to each request of the CA, which increases burden on link transmission; and in addition, one ACK packet needs to be additionally processed, which increases a delay of the entire request and reduces data processing efficiency. Therefore, it is necessary to provide a new method to solve the foregoing problem.